package com.learn.springcloud.hystrixexplainindetailconsumer.command.naming.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.web.client.RestTemplate;

/**
 * 注解方式实现的HystrixCommand的线程池划分
 * @Time : 2018/8/3 18:59
 * @Version : 1.0
 */
public class ThreadPoolPartitionAnnotationWay {

    private RestTemplate restTemplate;

    public ThreadPoolPartitionAnnotationWay(RestTemplate restTemplate) {
        this.restTemplate = restTemplate;
    }

    @HystrixCommand(fallbackMethod = "sayHelloFallback", groupKey = "111", commandKey = "222", threadPoolKey = "333")
    public String sayHello(String name){
        System.out.println("UserServiceException Running : " + name);
        String url = "http://hystrix-explain-in-detail-provider/request/command/say/hello?name={1}";
        return restTemplate.getForObject(url, String.class, name);
    }

    private String sayHelloFallback(String name){
        return "error, " + name;
    }

}
